package gui;
import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicComboBoxUI;

//Combo box with spectial lookout for this game
public class GameComboBox extends JComboBox{

	private static final long serialVersionUID = 1L;
	
	//With this constructor we can set the bounds of this component
	public GameComboBox(int x, int y, int width, int height){
	    setUI((ComboBoxUI) MyComboBoxUI.createUI(this));
	    setBounds(x, y, width, height);
	}
	
	//With this constructor we can set the datas stored by this component
	public GameComboBox(String[] param){
		super(param);
	    setUI((ComboBoxUI) MyComboBoxUI.createUI(this));
	}
	
	//Overriding this method to special lookout
	public void paintComponent(Graphics g){
		g.setColor(GameConstants.COMPONENT_TEXTBOX);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(GameConstants.COMPONENT_TEXTBOX_BORDER);
		g.drawRect(1, 1, getWidth()-getHeight()-3, getHeight()-3);
		g.setColor(GameConstants.COMPONENT_TEXT);
		if(this.getItemCount()!=0)
			g.drawString(
					getSelectedItem().toString(),
					5,
					getFontMetrics(getFont()).getHeight() + 2);
	}
	
	//Inner class for component parts
	public static class MyComboBoxUI extends BasicComboBoxUI {
		
		//Constructor for UI
		public static ComponentUI createUI(JComponent c) {
			return new MyComboBoxUI();
		}
		
		//Overriding the arrow button
		protected JButton createArrowButton() {
			JButton button = new GameArrowButton(); //new BasicArrowButton(BasicArrowButton.SOUTH);
			return button;
		}
	}

}